/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jebert.javamessage.control;

import java.io.DataInputStream;
import java.net.Socket;
import org.jebert.javamessage.model.Contact;
import org.jebert.javamessage.view.ChatWindow;
import org.jebert.javamessage.view.ContactList;

public class MessageServer extends Thread {

    private Socket msocket;
    private ContactList conlist;
    

    public MessageServer(Socket socket, ContactList contactlist) {
        this.msocket = socket;
        this.conlist = contactlist;
    }

    public void run() {
        while (true) {
            try {
                ChatWindow mchatwindow = conlist.getChatWindow(msocket.getInetAddress());
                mchatwindow.setVisible(true);
                Translator trans = mchatwindow.getWindowTranslator();
                Contact cnt = mchatwindow.getWindowContact();
                DataInputStream mess = new DataInputStream(msocket.getInputStream());
                String sockmessage = mess.readUTF();
                String mMessage = cnt.getContactName() + " " + trans.translateIt("Said:") + " " + trans.translateIt(sockmessage);
                
                mchatwindow.setLog(mMessage);
                System.out.println("Recebido Server");
                sleep(1000);
            } catch (Exception e) {
            }
        }

    }
}
